#!/bin/bash

source "`dirname $0`/appname.inc"

cd ${WorkDir}

if [ -s ${FlagFile} ];then
    exit 0
fi

if [ ! -s ${PidFile} ]
then
	echo "start ${AppName} at " `date +"%Y-%m-%d %H:%M:%S"` >> ../log/monitor.log
 	${StartCmd}
	cd ${CurrDir}
	exit 0
fi	

Pid=`cat ./${PidFile}`

Count=`ps uwww -p ${Pid} | grep -c ${AppName}`

if [ ${Count} -lt 1 ]
then
	echo "start ${AppName} at " `date +"%Y-%m-%d %H:%M:%S"` >> ../log/monitor.log
	${StartCmd}
fi

cd ${CurrDir}
